home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / turbovis / tvtoyc01.zip / VESA.CPP < prev    next >
C/C++ Source or Header  |  1994-01-12  |  6KB  |  221 lines

  1. /***************************************************************************
  2.   VESA unit
  3.   VESA video mode routines
  4.   PJB October 6, 1993, Internet mail to d91-pbr@nada.kth.se
  5.   Copyright PJB 1993, All Rights Reserved.
  6.   Free source, use at your own risk.
  7.   If modified, please state so if you pass this around.
  8.  
  9.   This unit has been tested in protected mode with a PD VESA TSR.
  10.   UNIVESA.EXE does not implement text mode support, so can't be used
  11.   to test with.
  12.  
  13.   You can overlay this unit if you want to.
  14.  
  15. ***************************************************************************/
  16.  
  17.  
  18. #include "video.h"
  19. #include "vesa.h"
  20. #include "toycfg.h"
  21.  
  22. const
  23.   VesaSignature vesaSig = "VESA";
  24.  
  25. ushort vesaVersion = 0;
  26. Boolean vesaScanningSupported=False;
  27. Boolean standardInfoAvailable=False;
  28.  
  29. /*******************************************************************
  30.   Get VESA information (signature, version, video modes)
  31. *******************************************************************/
  32. Boolean getVesaInfo(VesaInfoBlock *vesaInfo)
  33. {
  34.   asm{
  35.       mov  ax,0x4F00
  36.  
  37.      #ifdef DPMI
  38.       mov  bx,vesaInfo.Word+2
  39.       mov  RealModeRegs.TRealRegs.RealES,bx
  40.       mov  di,vesaInfo.Word
  41.       push 0x10
  42.       call DPMI.RealModeInterrupt
  43.      #else
  44.       les  di,vesaInfo
  45.       int  0x10
  46.      #endif
  47.  
  48.       cmp  ax,0x004F
  49.       mov  al,0
  50.       jnz  fin
  51.       inc  al
  52.   }
  53.  
  54.  fin:
  55.   return (Boolean)_AL;
  56. }
  57.  
  58.  
  59. /*******************************************************************
  60.   Retrieve VESA video mode information
  61. *******************************************************************/
  62. Boolean getVesaModeInfo(ushort mode, VesaModeInfo *buffer)
  63. {
  64.   asm{
  65.       mov  ax,0x4F01
  66.       mov  cx,mode
  67.  
  68.      #ifdef DPMI
  69.       mov  bx,buffer.Word+2
  70.       mov  RealModeRegs.TRealRegs.RealES,bx
  71.       mov  di,buffer.Word
  72.       push 0x10
  73.       call DPMI.RealModeInterrupt
  74.      #else
  75.       les  di,buffer
  76.       int  0x10
  77.      #endif
  78.  
  79.       cmp  ax,0x004F
  80.       mov  al,0
  81.       jnz  fin
  82.       inc  ax
  83.  
  84.   }
  85.  
  86.  fin:
  87.   return (Boolean)_AL;
  88. }
  89.  
  90.  
  91. /*******************************************************************
  92.   Set VESA video mode
  93. *******************************************************************/
  94. void setVesaMode(ushort mode)
  95. {
  96. asm{
  97.     mov  ax,0x4F02
  98.     mov  bx,mode
  99.     int  0x10
  100. }
  101. }
  102.  
  103.  
  104. /*******************************************************************
  105.   Retrieve current VESA video mode
  106. *******************************************************************/
  107. ushort getVesaMode()
  108. {
  109.   asm{
  110.       mov  ax,0x4F03
  111.       int  0x10
  112.       xchg ax,bx
  113.   }
  114.   return _AX;
  115. }
  116.  
  117.  
  118. /*******************************************************************
  119.   Get VESA version
  120. *******************************************************************/
  121. void detectVesaVersion()
  122. {
  123.  #ifdef DPMI
  124.   vesaInfo      : PVesaInfoBlock;
  125.   realBufferPtr : PVesaInfoBlock;
  126.  #else
  127.   VesaInfoBlock vesaInfo;
  128.  #endif
  129.  
  130.  #ifdef DPMI
  131.   if (!GetDosMem(Pointer(RealBufferPtr), Pointer(VesaInfo),
  132.          sizeof(VesaInfoBlock)) )
  133.     Exit;
  134.   if (GetVesaInfo(RealBufferPtr) and (VesaInfo->VesaSignature==VesaSig) )
  135.     VesaVersion=VesaInfo->VesaVersion;
  136.   GlobalDosFree(Seg(vesaInfo^));
  137.  #else
  138.   if (getVesaInfo(&vesaInfo) && (vesaInfo.vesaSignature==vesaSig))
  139.     vesaVersion=vesaInfo.vesaVersion;
  140.  #endif
  141. }
  142.  
  143.  
  144. /*******************************************************************
  145.   Determine available VESA text video modes
  146. *******************************************************************/
  147. void scanVesaModes(AddModeProc addMode)
  148. {
  149.   ushort *modes;
  150.  #ifdef DPMI
  151.   BufferPtr     : PVesaModeInfo;
  152.   RealBufferPtr : PVesaModeInfo;
  153.   VesaInfo      : PVesaInfoBlock ABSOLUTE BufferPtr;
  154.  #else
  155.   VesaModeInfo buffer;
  156.  #endif
  157.  
  158.  #ifdef DPMI
  159.   if( not GetDosMem(Pointer(RealBufferPtr), Pointer(BufferPtr),
  160.          SizeOf(VesaInfoBlock)) )
  161.     Exit;
  162.   GetVesaInfo(PVesaInfoBlock(RealBufferPtr));
  163.   Modes=DPMI.CreateRealModeSelector(VesaInfo->VideoModePtr, 0xFFFF);
  164.  #else
  165.   getVesaInfo((VesaInfoBlock*)&buffer);
  166.   modes=((VesaInfoBlock*)&buffer)->videoModePtr;
  167.  #endif
  168.  
  169.     while (*modes!=0xFFFF)
  170.     {
  171.      #ifdef DPMI
  172.       if (GetVesaModeInfo(*Modes, RealBufferPtr) )
  173.     with BufferPtr^ do
  174.      #else
  175.       if (getVesaModeInfo(*modes, &buffer))
  176.      #endif
  177.         if (buffer.attr.supported && !buffer.attr.graphics)
  178.           if (buffer.attr.optionalInfo)
  179.             addMode(*modes, buffer.height, buffer.width, buffer.charHeight,
  180.                   Boolean(buffer.attr.color==1));
  181.       else
  182.             switch (*modes)
  183.           case 2,3,7:
  184.                 addMode(*modes, 25, 80, 16, Boolean(*modes==3));
  185.  
  186.       modes++;
  187.     }
  188.  
  189.    #ifdef DPMI
  190.     FreeSelector(Seg(Modes^));
  191.     GlobalDosFree(Seg(BufferPtr^));
  192.    #endif
  193.   }
  194.  
  195.  
  196. /*******************************************************************
  197.   Used to test if VESA Get Video Mode Info supported
  198. *******************************************************************/
  199. #pragma argsused
  200. void far checkScanSupport(ushort mode, ushort rows, ushort columns, ushort charHeight, Boolean color)
  201. {
  202.   if (mode>7)
  203.     vesaScanningSupported=True;
  204.   else
  205.     standardInfoAvailable=False;
  206. }
  207.  
  208. /*******************************************************************
  209.   Test the hard way if( VESA get video mode info Boolean supported
  210. *******************************************************************/
  211. Boolean vesaScanningPossible()
  212. {
  213.   standardInfoAvailable=True;
  214.   if (vesaVersion)
  215.     scanVesaModes(checkScanSupport);
  216.   standardInfoAvailable=Boolean(!standardInfoAvailable);
  217.  
  218.   return vesaScanningSupported;
  219. }
  220.  
  221.